import net.spreadshirt.util.Observer;
import net.spreadshirt.util.Observable;
import net.spreadshirt.logger.Logger;
import net.spreadshirt.logger.LogMessage;

/**
 * An observer of the Logger class.
 * 
 * This class displays only error and fatal messages sent to the log
 * in a special info box module.
 */
class com.yourdomain.spreadshop.gui.mod.lib.ErrorLog implements Observer {

	// The log that this object is observing.
	private var log:net.spreadshirt.logger.Logger;

	// A reference to the text box module.
	private var call:Object;

	/**
	 * TextFieldView Constructor
	 */
	public function ErrorLog(l:Logger, c:Object) {
		log = l;
		call = c;
	}

	/**
	 * Invoked when the log changes.
	 * For details, see the Observer interface.
	 */
	public function update(o:Observable, infoObj:Object):Void {
		// Cast infoObj to a LogMessage instance for type checking.
		var logMsg:LogMessage = LogMessage(infoObj);
		// Display the log message in the log text field.
		var lev:String = Logger.getLevelDesc(logMsg.getLevel());
		if(lev == "FATAL" || lev == "ERROR") {
			var msg:String = "<b>"+ lev +" ERROR</b>\n"
				 + logMsg.getMessage() +"\n";
			call.obj[call.fnc](msg);
		}
	}

}